package com.xym.web.Service;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xym.bean.TaotaoResult;
import com.xym.common.Converter.SimpleResponseHandler;
import com.xym.pojo.Order;

@Service
public class OrderService {
	
	@Autowired
	private ApiService apiService;
	
	private final static ObjectMapper mapper=new ObjectMapper();

	/**
	 * 调用order系统接口
	 * @param order
	 * @return
	 * @throws Exception 
	 */
	public TaotaoResult submitOrder(Order order)  {
		try {
			String uri = "http://order.xym.com/order/create";
			String jsonUser = mapper.writeValueAsString(order);
			
			return apiService.doPostJson(uri, jsonUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TaotaoResult.build(500, "订单提交失败");
	}

	public Order queryOrderById(String orderId) {
		try {
			String uri="http://order.xym.com/order/query/31515243514049";
			String orderJson = this.apiService.doGet(uri);
			return mapper.readValue(orderJson, Order.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
 
	

}
